<?php

namespace Home\Controller;

use Think\Controller;
use Think\Crypt;

class GetController extends Controller {

    public function __construct() {
        parent::__construct();
    }

    public function uppass() {
        if (IS_AJAX) {
            $newpass = I('get.newpass');
            $renpass = I('get.renpass');
            $username = I('get.username');
            if ($newpass == '' || $renpass == '') {
                $this->ajaxReturn(array('ret' => 12, 'msg' => '密码不能为空！'), 'json');
            }
            if ($newpass != $renpass) {
                $this->ajaxReturn(array('ret' => 13, 'msg' => '两次密码输入不一至'), 'json');
            }
            $userModel = new \Home\Model\UserModel;
            $data['username'] = $username;
            $data['password'] = Crypt::Crypt_Hash_Create($newpass);
            //$User->where('id=5')->save($data);             
            if ($userModel->where("username='" . $username . "'")->save($data)) {
                $this->ajaxReturn(array('ret' => 0, 'msg' => '密码修改成功'));
            } else {
                $this->ajaxReturn(array('ret' => 1, 'msg' => '密码修改失败'));
            }
        }
        $uuid = I('get.uuid');
        $token = I('get.token');
        $username = I('get.username');
        $mem = memcache_connect('localhost', 11211);
        $tmp = $mem->get($uuid);
        if ($tmp && ($tmp == $token)) {
            //修改密码页面
            $this->assign('username', $username);
            $this->assign('on3a', 'on3a');
            $this->display("Member/uppass");
        }
    }

}
